package com.amado.webservice;

import java.io.IOException;
import java.rmi.RemoteException;

import javax.xml.bind.JAXBException;

import com.amado.webservice.create.XxfbptserviceStub;
import com.amado.webservice.entity.Response;
import com.amado.webservice.util.DESCorder;
import com.amado.webservice.util.XmlUtil;

public class Test {
	public String getUser() {
		XxfbptserviceStub.XxptSchudingResponse response = null;
		try {
			XxfbptserviceStub stub = new XxfbptserviceStub();
			XxfbptserviceStub.XxptSchuding parameter = new XxfbptserviceStub.XxptSchuding();
			parameter.setIn0("ZGLT");
			parameter.setIn1("ZGLT@2019");
			parameter.setIn2("J1");
			String xml = "<?xml version=”1.0”  encoding=”utf-8”?>\r\n" + "<request>\r\n" + "<head>\r\n"
					+ "<yhdh>123</yhdh>\r\n" + "<ip>192.168.0.1</ip>\r\n" + "<lsh>123</lsh>\r\n" + "</head>\r\n"
					+ "<body>\r\n" + "<sqm>MUH4T4RCS2NJJ3HTB5QEN6UNPL21ZL01</sqm>\r\n" + "</body>\r\n" + "</request>";
			// 加密参数
			parameter.setIn3(DESCorder.encryptModeToString("admin", "passw", xml));
			response = stub.xxptSchuding(parameter);

		} catch (RemoteException e) {
			e.printStackTrace();
		}
		String user = response.getOut();
		System.out.println("user = " + user);
		try {
			Response responseBean = XmlUtil.xmlToBean(user, Response.class);
			if ("0000".equals(responseBean.getCode())) {

			}
			// 解密参数（retrun>msg）
			String decryMsg = DESCorder.decryptMode("admin", "123", responseBean.getMsg());
			return decryMsg;
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		Test t = new Test();
		// 用户:小明
		System.out.println(t.getUser());
	}
}
